//
//  FirstViewController.m
//  UITextView
//
//  Created by gzjd on 2017/12/3.
//  Copyright © 2017年 gzjd. All rights reserved.
//

#import "FirstViewController.h"
#import "Masonry.h"
#import "LMJDropdownMenu.h"
@interface FirstViewController ()<LMJDropdownMenuDelegate>
@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //[self.view setbackgroundColor:[UIColor redColor]];
   [self.view setBackgroundColor:[UIColor redColor]];
//    self.navigationItem.title=@"第一个界面";
//    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"返回一" style:UIBarButtonItemStylePlain target:nil action:nil];
//    
//    CGRect rect = [[UIScreen mainScreen] bounds];
//    CGSize size = rect.size;
//    CGFloat width = size.width;
    LMJDropdownMenu * dropdownMenu = [[LMJDropdownMenu alloc] init];
    [dropdownMenu setFrame:CGRectMake(20, 80, 100, 40)];
    [dropdownMenu setMenuTitles:@[@"选项一",@"选项二",@"选项三",@"选项四",@"选项5"] rowHeight:30];
    dropdownMenu.delegate = self;
    [self.view addSubview:dropdownMenu];

    //self.navigationItem.titleView  = dropdownMenu;
//    UIButton  * textSearch = [[UIButton alloc] initWithFrame:CGRectMake(0, 7, width - 50, 25)];
//    //textSearch.placeholder     = @"在此输入查找内容";
//   // textSearch.textAlignment = NSTextAlignmentCenter;
//    //textSearch.leftViewMode    = UITextFieldViewModeAlways;
//    //[textSearch setTitle:<#(nullable NSString *)#> forState:<#(UIControlState)#>
//    [textSearch setTitle:@"在此输入查找内容" forState:UIControlStateNormal];
//    textSearch.backgroundColor = [UIColor whiteColor];
//    textSearch.layer.masksToBounds  = YES;
//    textSearch.layer.cornerRadius   = 12.5;
//    textSearch.titleLabel.font = [UIFont systemFontOfSize:16];
//    [textSearch setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [textSearch addTarget:self action:@selector(clickMainBtn:) forControlEvents:UIControlEventTouchUpInside];
//    
//    //textSearch.tintColor           = [UIColor blueColor];  //<span style="color:#ff0000;">如果不加此句则在ios7以上系统不显示光标</span>
//    
////    [textSearch addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
//    
//    self.navigationItem.titleView  = textSearch;
//    [self setMenuTitles:@[@"选项一",@"选项二",@"选项三",@"选项四",@"选项5"] rowHeight:30];
//    
//    
//    UIBarButtonItem *cancelButton =[[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(onCancel:)];
//    NSDictionary *textAttr = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
//    [cancelButton setTitleTextAttributes:textAttr forState:UIControlStateNormal];
//    
    //self.navigationItem.rightBarButtonItem  = cancelButton;
    
    
   // [textSearch becomeFirstResponder];
//    UIView* uv =[[UIView alloc]init];
//    /*initWithFrame:CGRectMake(mainSize.width / 2 - 211 / 2, 100, 211, 109)];*/
//    [uv setBackgroundColor:[UIColor redColor]];
//    [self.view addSubview:uv];
//    [uv mas_makeConstraints:^(MASConstraintMaker *make) {
////        make.size.mas_equalTo(CGSizeMake(100,110));
////        make.centerX.equalTo(self.view);
////        make.top.equalTo(self.view.mas_top).with.offset(110);
//        make.width.equalTo(self.view.mas_width);//设置宽度为self.view的一半，multipliedBy是倍数的意思，也就是，使宽度等于self.view宽度的0.5倍
//        make.height.equalTo(self.view.mas_height).multipliedBy(0.1);//设置高度为self.view高度的一半
//    }];
    // Do any additional setup after loading the view.
}

//
//- (void)clickMainBtn:(UIButton *)button{
//    
//    NSLog(@"hello");
//    // 将下拉视图添加到控件的俯视图上
//
//    self.listView.frame=CGRectMake(VIEW_X(self.listView), VIEW_Y(self.listView), VIEW_WIDTH(self.listView), self.rowHeight *self.titleArr.count);
//    self.tableView.frame = CGRectMake(0, 0, VIEW_WIDTH(self.listView), VIEW_HEIGHT(self.listView));
//[self.view addSubview:self.listView ];
//    //    if(button.selected == NO) {
////        [self showDropDown];
////    }
////    else {
////       /// [self hideDropDown];
////    }
//}
//
//- (void)showDropDown{   // 显示下拉列表
//    
//    [self.view bringSubviewToFront:self.listView]; // 将下拉列表置于最上层
//    
//    
//    
////    if ([self.delegate respondsToSelector:@selector(dropdownMenuWillShow:)]) {
////        [self.delegate dropdownMenuWillShow:self]; // 将要显示回调代理
////    }
//    
//    
//    [UIView animateWithDuration:AnimateTime animations:^{
//        
//       // _arrowMark.transform = CGAffineTransformMakeRotation(M_PI);
////        self.listView.frame=CGRectMake(VIEW_X(self.listView), VIEW_Y(self.listView), VIEW_WIDTH(self.listView), self.rowHeight *self.titleArr.count);
//        //self.tableView.frame = CGRectMake(0, 0, VIEW_WIDTH(self.listView), VIEW_HEIGHT(self.listView));
//        
//    }completion:^(BOOL finished) {
//        
////        if ([self.delegate respondsToSelector:@selector(dropdownMenuDidShow:)]) {
////            [self.delegate dropdownMenuDidShow:self]; // 已经显示回调代理
////        }
//    }];
//    
//    
//    
//   // _mainBtn.selected = YES;
//}
//- (void)setMenuTitles:(NSArray *)titlesArr rowHeight:(CGFloat)rowHeight{
////    if (self == nil) {
////        return;
////    }
//    self.titleArr  = [NSArray arrayWithArray:titlesArr];
//   // NSLog(<#NSString * _Nonnull format, ...#>);
//    self.rowHeight = rowHeight;
//    // 下拉列表背景View
//    self.listView = [[UIView alloc] init];
//    self.listView .frame = CGRectMake(VIEW_X(self.navigationItem.titleView) , VIEW_Y_Bottom(self.navigationItem.titleView), VIEW_WIDTH(self.navigationItem.titleView),  15);
//    self.listView .clipsToBounds       = YES;
//    self.listView .layer.masksToBounds = NO;
//    // _listView.layer.borderColor   = [UIColor redColor].CGColor;
//    self.listView .layer.borderWidth   = 0.5f;
//    
//    
//    // 下拉列表TableView
//    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,VIEW_WIDTH(self.listView ), VIEW_HEIGHT(self.listView ))];
////    tableView.delegate        = self;
////    tableView.dataSource      = self;
//    self.tableView.separatorStyle  = UITableViewCellSeparatorStyleNone;
//    self.tableView.bounces         = NO;
//    [self.listView  addSubview:self.tableView];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark - LMJDropdownMenu Delegate

- (void)dropdownMenu:(LMJDropdownMenu *)menu selectedCellNumber:(NSInteger)number{
    NSLog(@"你选择了：%ld",number);
}

- (void)dropdownMenuWillShow:(LMJDropdownMenu *)menu{
    NSLog(@"--将要显示--");
}
- (void)dropdownMenuDidShow:(LMJDropdownMenu *)menu{
    NSLog(@"--已经显示--");
}

- (void)dropdownMenuWillHidden:(LMJDropdownMenu *)menu{
    NSLog(@"--将要隐藏--");
}
- (void)dropdownMenuDidHidden:(LMJDropdownMenu *)menu{
    NSLog(@"--已经隐藏--");
}

@end
